/**
 * Copyright 2020 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "src/ops/upsample.h"
#include "src/ops/primitive_c.h"
#include "src/ops/populate/populate_register.h"
#include "nnacl/upsample_parameter.h"

namespace mindspore {
namespace lite {

OpParameter *PopulateUpsampleParameter(const mindspore::lite::PrimitiveC *primitive) {
  UpsampleParameter *upsample_parameter = reinterpret_cast<UpsampleParameter *>(malloc(sizeof(UpsampleParameter)));
  if (upsample_parameter == nullptr) {
    MS_LOG(ERROR) << "malloc Upsample Parameter failed.";
    return nullptr;
  }
  memset(upsample_parameter, 0, sizeof(UpsampleParameter));
  auto param = reinterpret_cast<mindspore::lite::Upsample *>(const_cast<mindspore::lite::PrimitiveC *>(primitive));
  upsample_parameter->op_parameter_.type_ = primitive->Type();
  auto method = param->GetMode();
  if (method == "linear") {
    upsample_parameter->method_ = 0;
  } else {
    upsample_parameter->method_ = 1;
  }
  return reinterpret_cast<OpParameter *>(upsample_parameter);
}
Registry UpsampleParemeterRegistry(schema::PrimitiveType_Upsample, PopulateUpsampleParameter);
}  // namespace lite
}  // namespace mindspore
